package com.wenhai.spring.aop.features.pointcut;

import org.springframework.aop.support.StaticMethodMatcherPointcut;
import org.springframework.lang.NonNull;

import java.lang.reflect.Method;
import java.util.Objects;

/**
 * @ClassName EchoServicePointcut
 * @Description
 * @Author 谢文海
 * @Date 2021/3/5 20:07
 * @Version 1.0
 **/
public class EchoServicePointcut extends StaticMethodMatcherPointcut {

    private String    methodName;
    private Class<?>  targetClass;


    public EchoServicePointcut(String methodName, Class<?> targetClass) {
        this.methodName  = methodName;
        this.targetClass = targetClass;
    }

    @Override
    public boolean matches(@NonNull Method method, @NonNull Class<?> targetClass) {
        return Objects.equals(method.getName(), methodName) && this.targetClass.isAssignableFrom(targetClass);
    }

}
